using System;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.Web.Management.Client;
using Microsoft.Web.Management.Client.Win32;
using Microsoft.Web.Management.Server;

namespace Microsoft.Web.Management.Iis.Client
{
    // Create a new GUID for your page. In Visual Sudio, use "Tools|Create GUID"
    [ModulePageIdentifier("855E9D40-6147-4f5d-A9C9-AA57FCFEC41D")]
    internal sealed class ServerLoggingPage : ModuleDialogPage
    {
        /************************************************************************
           FIELDS
         ************************************************************************/
        PropertyBag                 _properties     = new PropertyBag();
        LoggingModuleServiceProxy   _moduleProxy;
        TaskList                    _taskList;
        Boolean                     _hasChanges;
#pragma warning disable 649
        Boolean                     _isReadOnly;
#pragma warning restore 649

        // Http Logging
        Boolean                     _dontLog;
        SelectiveLogging            _selectiveLogging;
        Boolean                     _httpLoggingIsLocked;

        // Application Host Logging
        LoggingMode                 _loggingMode;
        Boolean                     _logInUtf8;
        Boolean                     _ahLoggingIsLocked;

        /************************************************************************
           CONSTRUCTORS
         ************************************************************************/
        public ServerLoggingPage()
        {
            InitializeComponent();
        }

        /************************************************************************
           PROPERTIES
         ************************************************************************/
        protected override bool CanApplyChanges
        {
            get { return HasChanges; }
        }
        protected override bool CanRefresh
        {
            get { return true; }
        }
        protected override bool HasChanges
        {
            get { return _hasChanges; }
        }
// ReSharper disable UnusedMember.Local
        private bool IsLoggingDisabled
        {
            get { return _dontLog; }
        }
// ReSharper restore UnusedMember.Local
        protected override bool ReadOnly
        {
            get { return _isReadOnly; }
        }
        protected override TaskListCollection Tasks
        {
            get
            {
                if (_taskList == null)
                {
                    _taskList = new PageTaskList(this);
                }
                TaskListCollection col = base.Tasks;
                col.Add(_taskList);
                return col;
            }
        }

        /************************************************************************
           METHODS                                                              
         ************************************************************************/
        /// <summary>
        /// Applies pending changes to the configuration system.
        /// </summary>
        /// <returns></returns>
        protected override bool ApplyChanges()
        {
            Boolean temp;
            GetSettingsFromUi();
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                
                var logProperties = (PropertyBag)_properties[LoggingPropertyIndexes.LOG_ELEMENT_INDEX];
                _moduleProxy.UpdateApplicationHostLogSettings(logProperties);

                var httpProperties = (PropertyBag)_properties[LoggingPropertyIndexes.HTTP_ELEMENT_INDEX];
                _moduleProxy.UpdateHttpLogSettings(httpProperties);

                temp = true;
            }
            catch (Exception ex)
            {
                DisplayErrorMessage(ex, Resources.ResourceManager);
                temp = false;
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                _hasChanges = false;
                UpdateState(false);
                Update();
            }

            return temp;
        }

        /// <summary>
        /// Begins a request to get properties from the module service proxy.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BeginGetProperties(object sender, DoWorkEventArgs e)
        {
            e.Result = _moduleProxy.GetConfigurationSettings();
        }

        /// <summary>
        /// Cancels any pending changes to the UI and resets the page
        /// </summary>
        protected override void CancelChanges()
        {
            InitializeUi();
            _hasChanges = false;
            Update();
        }

        /// <summary>
        /// Navigates to the configuration page for the specified Logging Mode
        /// </summary>
        /// <param name="mode"></param>
        public void ConfigureSettings(LoggingMode mode)
        {
            var bag1 = new PropertyBag();
            bag1[0] = mode;
            Navigate(typeof(CentralLoggingPage), bag1);
        }

        /// <summary>
        /// Ends a request to get properties from the module service proxy.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EndGetProperties(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                _properties = e.Result as PropertyBag;
                if (_properties != null)
                {
                    var httpProperties = (PropertyBag)_properties[LoggingPropertyIndexes.HTTP_ELEMENT_INDEX];
                    var logProperties = (PropertyBag)_properties[LoggingPropertyIndexes.LOG_ELEMENT_INDEX];

                    _dontLog = (Boolean)httpProperties[LoggingPropertyIndexes.HTTP_DONT_LOG_INDEX];
                    _selectiveLogging = (SelectiveLogging)httpProperties[LoggingPropertyIndexes.HTTP_SELECTIVE_LOGGING_INDEX];
                    _httpLoggingIsLocked = (Boolean)httpProperties[LoggingPropertyIndexes.IS_LOCKED_INDEX];

                    _loggingMode = (LoggingMode)logProperties[LoggingPropertyIndexes.CENTRAL_LOG_FILE_MODE_INDEX];
                    _logInUtf8 = (Boolean)logProperties[LoggingPropertyIndexes.CENTRAL_LOG_IN_UTF8_INDEX];
                    _ahLoggingIsLocked = (Boolean)logProperties[LoggingPropertyIndexes.IS_LOCKED_INDEX];

                    InitializeUi();
                }
            }
            catch(Exception exception)
            {
                MessageBox.Show(exception.ToString());
                // TODO: Handle exception case.
                // BUG: Handle exception case.
            }
        }

        /// <summary>
        /// Executes a request for configuration data asynchronously
        /// </summary>
        private void GetSettings()
        {
            StartAsyncTask(
                Resources.LoggingGettingSettings,
                BeginGetProperties,
                EndGetProperties);
            _hasChanges = false;
            Update();
        }

        /// <summary>
        /// Updates the property bags with the settings from the user interface.
        /// </summary>
        private void GetSettingsFromUi()
        {
            // Update all settings based on the user interface.
            //
            _dontLog = !_enableLoggingCheckBox.Checked;
            _logInUtf8 = _logInUtf8CheckBox.Checked;
            if (_loggingModeCentralBinaryRadioButton.Checked)
            {
                _loggingMode = LoggingMode.Binary;
            }
            else if (_loggingModeSiteRadioButton.Checked)
            {
                _loggingMode = LoggingMode.Site;
            }
            else if (_loggingModeCentralW3CRadioButton.Checked)
            {
                _loggingMode = LoggingMode.W3C;
            }

            if (_resourcesToLogAllRadioButton.Checked)
            {
                _selectiveLogging = SelectiveLogging.LogAll;
            }
            else if (_resourcesToLogFailedRadioButton.Checked)
            {
                _selectiveLogging = SelectiveLogging.LogError;
            }
            else if (_resourcesToLogSuccessfulRadioButton.Checked)
            {
                _selectiveLogging = SelectiveLogging.LogSuccessful;
            }

            // Update the property bag with the new settings
            //
            var logProperties = (PropertyBag)_properties[LoggingPropertyIndexes.LOG_ELEMENT_INDEX];
            logProperties[LoggingPropertyIndexes.CENTRAL_LOG_FILE_MODE_INDEX] = _loggingMode;
            logProperties[LoggingPropertyIndexes.CENTRAL_LOG_IN_UTF8_INDEX] = _logInUtf8;
            var httpProperties = (PropertyBag)_properties[LoggingPropertyIndexes.HTTP_ELEMENT_INDEX];
            httpProperties[LoggingPropertyIndexes.HTTP_DONT_LOG_INDEX] = _dontLog;
            httpProperties[LoggingPropertyIndexes.HTTP_SELECTIVE_LOGGING_INDEX] = _selectiveLogging;

            _properties[LoggingPropertyIndexes.LOG_ELEMENT_INDEX] = logProperties;
            _properties[LoggingPropertyIndexes.HTTP_ELEMENT_INDEX] = httpProperties;
        }


        /// <summary>
        /// Sets up the User Interface with the values received from the IIS configuration system.
        /// </summary>
        private void InitializeUi()
        {
            _enableLoggingCheckBox.Checked = !_dontLog;
            _logInUtf8CheckBox.Checked = _logInUtf8;
            switch (_loggingMode)
            {
                case LoggingMode.Binary:
                    _loggingModeCentralBinaryRadioButton.Checked = true;
                    break;
                case LoggingMode.Site :
                    _loggingModeSiteRadioButton.Checked = true;
                    break;
                case LoggingMode.W3C :
                    _loggingModeCentralW3CRadioButton.Checked = true;
                    break;
            }
            switch (_selectiveLogging)
            {
                case SelectiveLogging.LogAll:
                    _resourcesToLogAllRadioButton.Checked = true;
                    break;
                case SelectiveLogging.LogError:
                    _resourcesToLogFailedRadioButton.Checked = true;
                    break;
                case SelectiveLogging.LogSuccessful :
                    _resourcesToLogSuccessfulRadioButton.Checked = true;
                    break;
            }
            _resourcesToLogGroupBox.Enabled = !_httpLoggingIsLocked;
            _loggingModeGroupBox.Enabled = !_ahLoggingIsLocked;

            _hasChanges = false;
            SetToolTips();
            Update();
        }

        /// <summary>
        /// Handles page activation.
        /// </summary>
        /// <param name="initialActivation"></param>
        protected override void OnActivated(bool initialActivation)
        {
            base.OnActivated(initialActivation);
            _moduleProxy = (LoggingModuleServiceProxy)CreateProxy(typeof(LoggingModuleServiceProxy));
            GetSettings();
        }

        /// <summary>
        /// Sets tooltips on all of the user interface elements.
        /// </summary>
        private void SetToolTips()
        {
            _toolTip1.SetToolTip(_enableLoggingCheckBox, 
                String.Format(
                    "<system.webServer>\r\n  <httpLogging dontLog=\"{0}\" />\r\n</system.webServer>", 
                    !_enableLoggingCheckBox.Checked));

            _toolTip1.SetToolTip(_resourcesToLogAllRadioButton, 
                    "<system.webServer>\r\n  <httpLogging selectiveLogging=\"LogAll\"/>\r\n</system.webServer>");

            _toolTip1.SetToolTip(_resourcesToLogFailedRadioButton, 
                "<system.webServer>\r\n  <httpLogging selectiveLogging=\"LogError\"/>\r\n</system.webServer>");

            _toolTip1.SetToolTip(_resourcesToLogSuccessfulRadioButton, 
                "<system.webServer>\r\n  <httpLogging selectiveLogging=\"LogSuccessful\"/>\r\n</system.webServer>");

            _toolTip1.SetToolTip(_loggingModeSiteRadioButton, 
                "<system.applicationHost>\r\n  <log centralLogFileMode=\"Site\"/>\r\n</system.applicationHost>");
            
            _toolTip1.SetToolTip(_loggingModeCentralBinaryRadioButton, 
                "<system.applicationHost>\r\n  <log centralLogFileMode=\"CentralBinary\"/>\r\n</system.applicationHost>");

            _toolTip1.SetToolTip(_loggingModeCentralW3CRadioButton, 
                "<system.applicationHost>\r\n  <log centralLogFileMode=\"CentralW3c\"/>\r\n</system.applicationHost>");

            _toolTip1.SetToolTip(_logInUtf8CheckBox, 
                String.Format( 
                    "<system.webServer>\r\n  <httpLogging logInUTF8=\"{0}\" />\r\n</system.webServer>",
                    _logInUtf8CheckBox.Checked));
        }

        /// <summary>
        /// Updates the pending changes status
        /// </summary>
        /// <param name="isDirty"></param>
        private void UpdateState(bool isDirty)
        {
            _hasChanges = (_hasChanges || isDirty);
            SetToolTips();
            Update();
        }

        
        private GroupBox _serverLoggingSettingsGroupBox;
        private CheckBox _enableLoggingCheckBox;
        private Panel _pnlLogFileFormat;
        private GroupBox _loggingModeGroupBox;
        private RadioButton _loggingModeSiteRadioButton;
        private GroupBox _resourcesToLogGroupBox;
        private RadioButton _resourcesToLogSuccessfulRadioButton;
        private RadioButton _resourcesToLogFailedRadioButton;
        private RadioButton _resourcesToLogAllRadioButton;
        private CheckBox _logInUtf8CheckBox;
        private RadioButton _loggingModeCentralW3CRadioButton;
        private RadioButton _loggingModeCentralBinaryRadioButton;
        private ToolTip _toolTip1;
            
        

        private void InitializeComponent()
        {
            _serverLoggingSettingsGroupBox = new GroupBox();
            _enableLoggingCheckBox = new CheckBox();
            _pnlLogFileFormat = new Panel();
            _resourcesToLogGroupBox = new GroupBox();
            _resourcesToLogAllRadioButton = new RadioButton();
            _resourcesToLogFailedRadioButton = new RadioButton();
            _resourcesToLogSuccessfulRadioButton = new RadioButton();
            _loggingModeGroupBox = new GroupBox();
            _loggingModeSiteRadioButton = new RadioButton();
            _loggingModeCentralBinaryRadioButton = new RadioButton();
            _loggingModeCentralW3CRadioButton = new RadioButton();
            _logInUtf8CheckBox = new CheckBox();
            _toolTip1 = new ToolTip();
            _serverLoggingSettingsGroupBox.SuspendLayout();
            _pnlLogFileFormat.SuspendLayout();
            _resourcesToLogGroupBox.SuspendLayout();
            _loggingModeGroupBox.SuspendLayout();
            SuspendLayout();
            // 
            // serverLoggingSettingsGroupBox
            // 
            _serverLoggingSettingsGroupBox.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom)
                                                    | AnchorStyles.Left;
            _serverLoggingSettingsGroupBox.Controls.Add(_pnlLogFileFormat);
            _serverLoggingSettingsGroupBox.Controls.Add(_enableLoggingCheckBox);
            _serverLoggingSettingsGroupBox.Location = new System.Drawing.Point(4, 5);
            _serverLoggingSettingsGroupBox.Name = "_serverLoggingSettingsGroupBox";
            _serverLoggingSettingsGroupBox.Size = new System.Drawing.Size(285, 150);
            _serverLoggingSettingsGroupBox.TabIndex = 2;
            _serverLoggingSettingsGroupBox.TabStop = false;
            _serverLoggingSettingsGroupBox.Text = Resources.LoggingUiPageServerLoggingSettingsGroupBox;
            // 
            // enableLoggingCheckBox
            // 
            _enableLoggingCheckBox.AutoSize = true;
            _enableLoggingCheckBox.Location = new System.Drawing.Point(9, 20);
            _enableLoggingCheckBox.Name = "_enableLoggingCheckBox";
            _enableLoggingCheckBox.Size = new System.Drawing.Size(100, 17);
            _enableLoggingCheckBox.TabIndex = 0;
            _enableLoggingCheckBox.Text = Resources.LoggingUiPageEnableLoggingChexBox;
            _enableLoggingCheckBox.UseVisualStyleBackColor = true;
            _enableLoggingCheckBox.CheckedChanged += OnEnableLoggingCheckBoxCheckedChanged;
            // 
            // pnlLogFileFormat
            // 
            _pnlLogFileFormat.Anchor = ((AnchorStyles.Top | AnchorStyles.Bottom)
                                        | AnchorStyles.Left)
                                       | AnchorStyles.Right;
            _pnlLogFileFormat.Controls.Add(_logInUtf8CheckBox);
            _pnlLogFileFormat.Controls.Add(_loggingModeGroupBox);
            _pnlLogFileFormat.Controls.Add(_resourcesToLogGroupBox);
            _pnlLogFileFormat.Enabled = false;
            _pnlLogFileFormat.Location = new System.Drawing.Point(24, 44);
            _pnlLogFileFormat.Name = "_pnlLogFileFormat";
            _pnlLogFileFormat.Size = new System.Drawing.Size(253, 100);
            _pnlLogFileFormat.TabIndex = 1;
            // 
            // resourcesToLogGroupBox
            // 
            _resourcesToLogGroupBox.Anchor = (AnchorStyles.Top | AnchorStyles.Left)
                                             | AnchorStyles.Right;
            _resourcesToLogGroupBox.Controls.Add(_resourcesToLogSuccessfulRadioButton);
            _resourcesToLogGroupBox.Controls.Add(_resourcesToLogFailedRadioButton);
            _resourcesToLogGroupBox.Controls.Add(_resourcesToLogAllRadioButton);
            _resourcesToLogGroupBox.Location = new System.Drawing.Point(4, 4);
            _resourcesToLogGroupBox.Name = "_resourcesToLogGroupBox";
            _resourcesToLogGroupBox.Size = new System.Drawing.Size(239, 94);
            _resourcesToLogGroupBox.TabIndex = 0;
            _resourcesToLogGroupBox.TabStop = false;
            _resourcesToLogGroupBox.Text = Resources.LoggingUiPageResourcesToLogGroupBox;
            // 
            // resourcesToLogAllRadioButton
            // 
            _resourcesToLogAllRadioButton.AutoSize = true;
            _resourcesToLogAllRadioButton.Location = new System.Drawing.Point(6, 19);
            _resourcesToLogAllRadioButton.Name = "_resourcesToLogAllRadioButton";
            _resourcesToLogAllRadioButton.Size = new System.Drawing.Size(36, 17);
            _resourcesToLogAllRadioButton.TabIndex = 0;
            _resourcesToLogAllRadioButton.TabStop = true;
            _resourcesToLogAllRadioButton.Text = Resources.LoggingUiPageResourcesToLogAllRadioButton;
            _resourcesToLogAllRadioButton.UseVisualStyleBackColor = true;
            _resourcesToLogAllRadioButton.CheckedChanged += OnResourcesToLogAllRadioButtonCheckedChanged;
            // 
            // resourcesToLogFailedRadioButton
            // 
            _resourcesToLogFailedRadioButton.AutoSize = true;
            _resourcesToLogFailedRadioButton.Location = new System.Drawing.Point(7, 43);
            _resourcesToLogFailedRadioButton.Name = "_resourcesToLogFailedRadioButton";
            _resourcesToLogFailedRadioButton.Size = new System.Drawing.Size(118, 17);
            _resourcesToLogFailedRadioButton.TabIndex = 1;
            _resourcesToLogFailedRadioButton.TabStop = true;
            _resourcesToLogFailedRadioButton.Text = Resources.LoggingUiPageResourcesToLogFailedRadioButton;
            _resourcesToLogFailedRadioButton.UseVisualStyleBackColor = true;
            _resourcesToLogFailedRadioButton.CheckedChanged += OnResourcesToLogFailedRadioButtonCheckedChanged;
            // 
            // resourcesToLogSuccessfulRadioButton
            // 
            _resourcesToLogSuccessfulRadioButton.AutoSize = true;
            _resourcesToLogSuccessfulRadioButton.Location = new System.Drawing.Point(7, 67);
            _resourcesToLogSuccessfulRadioButton.Name = "_resourcesToLogSuccessfulRadioButton";
            _resourcesToLogSuccessfulRadioButton.Size = new System.Drawing.Size(142, 17);
            _resourcesToLogSuccessfulRadioButton.TabIndex = 2;
            _resourcesToLogSuccessfulRadioButton.TabStop = true;
            _resourcesToLogSuccessfulRadioButton.Text = Resources.LoggingUiPageResourcesToLogSuccessRadioButton;
            _resourcesToLogSuccessfulRadioButton.UseVisualStyleBackColor = true;
            _resourcesToLogSuccessfulRadioButton.CheckedChanged += OnResourcesToLogSuccessfulRadioButtonCheckedChanged;
            // 
            // loggingModeGroupBox
            // 
            _loggingModeGroupBox.Anchor = (AnchorStyles.Top | AnchorStyles.Left)
                                          | AnchorStyles.Right;
            _loggingModeGroupBox.Controls.Add(_loggingModeCentralW3CRadioButton);
            _loggingModeGroupBox.Controls.Add(_loggingModeCentralBinaryRadioButton);
            _loggingModeGroupBox.Controls.Add(_loggingModeSiteRadioButton);
            _loggingModeGroupBox.Location = new System.Drawing.Point(4, 105);
            _loggingModeGroupBox.Name = "_loggingModeGroupBox";
            _loggingModeGroupBox.Size = new System.Drawing.Size(239, 93);
            _loggingModeGroupBox.TabIndex = 1;
            _loggingModeGroupBox.TabStop = false;
            _loggingModeGroupBox.Text = Resources.LoggingUiPageLoggignModeGroupBox;
            // 
            // loggingModeSiteRadioButton
            // 
            _loggingModeSiteRadioButton.AutoSize = true;
            _loggingModeSiteRadioButton.Location = new System.Drawing.Point(7, 20);
            _loggingModeSiteRadioButton.Name = "_loggingModeSiteRadioButton";
            _loggingModeSiteRadioButton.Size = new System.Drawing.Size(63, 17);
            _loggingModeSiteRadioButton.TabIndex = 0;
            _loggingModeSiteRadioButton.TabStop = true;
            _loggingModeSiteRadioButton.Text = Resources.LoggingUiPageLoggingModeSiteRadioButton;
            _loggingModeSiteRadioButton.UseVisualStyleBackColor = true;
            _loggingModeSiteRadioButton.CheckedChanged += OnLoggingModeSiteRadioButtonCheckedChanged;
            // 
            // loggingModeCentralBinaryRadioButton
            // 
            _loggingModeCentralBinaryRadioButton.AutoSize = true;
            _loggingModeCentralBinaryRadioButton.Location = new System.Drawing.Point(7, 44);
            _loggingModeCentralBinaryRadioButton.Name = "_loggingModeCentralBinaryRadioButton";
            _loggingModeCentralBinaryRadioButton.Size = new System.Drawing.Size(89, 17);
            _loggingModeCentralBinaryRadioButton.TabIndex = 1;
            _loggingModeCentralBinaryRadioButton.TabStop = true;
            _loggingModeCentralBinaryRadioButton.Text = Resources.LoggingUiPageLoggingModeCentralBinaryRadioButton;
            _loggingModeCentralBinaryRadioButton.UseVisualStyleBackColor = true;
            _loggingModeCentralBinaryRadioButton.CheckedChanged += OnLoggingModeCentralBinaryRadioButtonCheckedChanged;
            // 
            // loggingModeCentralW3cRadioButton
            // 
            _loggingModeCentralW3CRadioButton.AutoSize = true;
            _loggingModeCentralW3CRadioButton.Location = new System.Drawing.Point(7, 69);
            _loggingModeCentralW3CRadioButton.Name = "_loggingModeCentralW3CRadioButton";
            _loggingModeCentralW3CRadioButton.Size = new System.Drawing.Size(85, 17);
            _loggingModeCentralW3CRadioButton.TabIndex = 2;
            _loggingModeCentralW3CRadioButton.TabStop = true;
            _loggingModeCentralW3CRadioButton.Text = Resources.LoggingUiPageLoggingModeCentralW3cRadioButton;
            _loggingModeCentralW3CRadioButton.UseVisualStyleBackColor = true;
            _loggingModeCentralW3CRadioButton.CheckedChanged += OnLoggingModeCentralW3CRadioButtonCheckedChanged;
            // 
            // logInUtf8CheckBox
            // 
            _logInUtf8CheckBox.AutoSize = true;
            _logInUtf8CheckBox.Location = new System.Drawing.Point(4, 204);
            _logInUtf8CheckBox.Name = "_logInUtf8CheckBox";
            _logInUtf8CheckBox.Size = new System.Drawing.Size(88, 17);
            _logInUtf8CheckBox.TabIndex = 2;
            _logInUtf8CheckBox.Text = Resources.LoggingUiPageLogInUtf8CheckBox;
            _logInUtf8CheckBox.UseVisualStyleBackColor = true;
            _logInUtf8CheckBox.CheckedChanged += OnLogInUtf8CheckBoxCheckedChanged;
            // 
            // ServerLogging
            // 
            AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            AutoScaleMode = AutoScaleMode.Font;
            ClientSize = new System.Drawing.Size(437, 324);
            Controls.Add(_serverLoggingSettingsGroupBox);
            Name = "ServerLogging";
            Text = Resources.LoggingUiPageServerLoggingTitle;
            _serverLoggingSettingsGroupBox.ResumeLayout(false);
            _serverLoggingSettingsGroupBox.PerformLayout();
            _pnlLogFileFormat.ResumeLayout(false);
            _pnlLogFileFormat.PerformLayout();
            _resourcesToLogGroupBox.ResumeLayout(false);
            _resourcesToLogGroupBox.PerformLayout();
            _loggingModeGroupBox.ResumeLayout(false);
            _loggingModeGroupBox.PerformLayout();
            ResumeLayout(false);
        }

        /************************************************************************
           EVENTS                                                             
         ************************************************************************/
        private void OnEnableLoggingCheckBoxCheckedChanged(object sender, EventArgs e)
        {
            _pnlLogFileFormat.Enabled = _enableLoggingCheckBox.Checked;
            UpdateState(true);
        }
        private void OnResourcesToLogAllRadioButtonCheckedChanged(object sender, EventArgs e)
        {
            UpdateState(true);
        }
        private void OnResourcesToLogFailedRadioButtonCheckedChanged(object sender, EventArgs e)
        {
            UpdateState(true);
        }
        private void OnResourcesToLogSuccessfulRadioButtonCheckedChanged(object sender, EventArgs e)
        {
            UpdateState(true);
        }
        private void OnLoggingModeSiteRadioButtonCheckedChanged(object sender, EventArgs e)
        {
            UpdateState(true);
        }
        private void OnLoggingModeCentralBinaryRadioButtonCheckedChanged(object sender, EventArgs e)
        {
            UpdateState(true);
        }
        private void OnLoggingModeCentralW3CRadioButtonCheckedChanged(object sender, EventArgs e)
        {
            UpdateState(true);
        }
        private void OnLogInUtf8CheckBoxCheckedChanged(object sender, EventArgs e)
        {
            UpdateState(true);
        }


        /************************************************************************
           Internal Classes                                                             
         ************************************************************************/
        /// <summary>
        /// Internal class used to create the page task list 
        /// </summary>
        private sealed class PageTaskList : TaskList
        {
            readonly ServerLoggingPage _owner;

            public PageTaskList(ServerLoggingPage owner)
            {
                _owner = owner;
            }

            public override ICollection GetTaskItems()
            {
                var list = new ArrayList();
                var cfgSiteDefaults = new MethodTaskItem("ConfigureSiteDefaults",
                    Resources.ConfigureSiteDefaults, "Configure", null, null);
                var cfgCentralBinary = new MethodTaskItem("ConfigureCentralBinary",
                    Resources.ConfigureCentralBinary, "Configure", null, null);
                var cfgCentralW3C = new MethodTaskItem("ConfigureCentralW3C",
                    Resources.ConfigureCentralW3C, "Configure", null, null);
                cfgSiteDefaults.Enabled = _owner._loggingModeSiteRadioButton.Checked && !_owner._hasChanges;
                cfgCentralBinary.Enabled = _owner._loggingModeCentralBinaryRadioButton.Checked && !_owner._hasChanges;
                cfgCentralW3C.Enabled = _owner._loggingModeCentralW3CRadioButton.Checked && !_owner._hasChanges;

                list.Add(cfgSiteDefaults);
                list.Add(cfgCentralBinary);
                list.Add(cfgCentralW3C);

                return list.ToArray(typeof(TaskItem));
            }
// ReSharper disable UnusedMember.Local
            public void ConfigureSiteDefaults()
            {
                _owner.ConfigureSettings(LoggingMode.Site);
            }
            public void ConfigureCentralBinary()
            {
                _owner.ConfigureSettings(LoggingMode.Binary );
            }
            public void ConfigureCentralW3C()
            {
                _owner.ConfigureSettings(LoggingMode.W3C);
            }
// ReSharper restore UnusedMember.Local
        }
    }
}
